using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using FinanceStats.Entities;
using FinanceStats.Business;

namespace FinanceStats
{
    public partial class EditGroup : Form
    {
        private OutcomeGroup outcomeGroup;

        public OutcomeGroup OutcomeGroup
        {
            get { return outcomeGroup; }
            set 
            { 
                outcomeGroup = value;
                Binding b = new Binding("Text", value, "GroupName", false, DataSourceUpdateMode.OnPropertyChanged);
                textBox1.DataBindings.Clear();
                textBox1.DataBindings.Add(b);
            }
        }
        
        public EditGroup()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void EditGroup_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            bool res = true;
            if (outcomeGroup.GroupID == null)
            {
                res = DataManager.Instance.InsertOutcomeGroup(this.outcomeGroup);
            }
            else
            {
                res = DataManager.Instance.UpdateOutcomeGroup(this.outcomeGroup);
            }
            this.DialogResult = res ? DialogResult.OK : DialogResult.No;
            this.Close();
        }
    }
}